﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem1
{
    class ClientManager
    {
        private List<Client> list; 
        static private ClientManager cm;
        private ClientManager()
        {
            this.list =  new List<Client>(); 
        }
        static public ClientManager getInstance()
        {
            if (cm == null)
                cm = new ClientManager();
            return cm; 
        }

        private Client searchClient(String nume)
        { 
            return list.Find(X => X.Nume.Equals(nume));

        }

        public void addCar(String numeClient, String model, String culoare)
        {
            Client c = searchClient(numeClient);
            if (c == null)
            {
                Console.WriteLine("clientul nu este de gasit");
                return; 
            }
            AbstractCar car=null;
            switch (model)
            {
                case "SedanA":
                    car = FactoryA.getInstance().createSedan(culoare);
                    break;
                case "SedanB":
                    car = FactoryB.getInstance().createSedan(culoare);
                    break;
                case "CoupeA":
                    car = FactoryA.getInstance().createCoupe(culoare);
                    break;
                case "CoupeB":
                    car = FactoryB.getInstance().createCoupe(culoare);
                    break;
                case "MiniA":
                    car = FactoryA.getInstance().createMini(culoare);
                    break;
                case "MiniB":
                    car = FactoryB.getInstance().createMini(culoare);
                    break;
            }
            if (car == null)
            {
                Console.WriteLine("modelul nu se gaseste in productie");
                return ;
            }

            c.addMasina(car);
            ObjectPool.getInstance().checkIn(car);
            Console.WriteLine("masina" + car.ToString()+" a fost vanduta cu succes!");
        }

        public void stergeMasina(String client,String model,String culoare)
        {
            Client c = searchClient(client);
            if (c == null)
            {
                Console.WriteLine("clientul nu este de gasit");
                return;
            }
            AbstractCar car = ObjectPool.getInstance().checkOut(model, culoare);
            if (car == null)
            {
                Console.WriteLine("masina inca nu a fost creata");
                return; 
            }
            c.deleteMasina(car);
            

        }

        public void addClient(String nume, int varsta)
        {
            Client c = new Client(nume,varsta);
            this.list.Add(c);
        }
        
    }
}
